#include "mainscene.h"
#include "ui_mainscene.h"
#include "config.h"
#include "mypushbutton.h"
#include <QPainter>
#include <QPixmap>
#include <QDebug>

MainScene::MainScene(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);

    //初始化场景
    initScene();
}

void MainScene::initScene()
{
    //初始化窗口大小
    setFixedSize(GAME_WIDTH,GAME_HEIGTH);

    //设置窗口标题
    setWindowTitle(GAME_TITLE);

    //加载图标
    setWindowIcon(QIcon(GAME_ICON));

    //创建关卡场景
    this->playscene = new PlayScene;

    //创建介绍场景
    this->introscene = new IntroScene;

    //创建开始按钮
    MyPushButton* startBtn = new MyPushButton(GAME_SATRT_BTN);
    startBtn->setParent(this);
    startBtn->move(this->width()*0.60,this->height()*0.25);
    connect(startBtn,&MyPushButton::clicked,[=](){
        //qDebug()<<"进入开始场景";

        this->playscene->show();//游戏场景显示
        this->hide();//自身隐藏
    });

    //创建介绍按钮
    MyPushButton* introBtn = new MyPushButton(GAME_INTRO_BTN);
    introBtn->setParent(this);
    introBtn->move(this->width()*0.60,this->height()*0.5);
    connect(introBtn,&MyPushButton::clicked,[=](){
        //qDebug()<<"进入介绍场景";

        this->introscene->show();
        this->hide();
    });


}

void MainScene::paintEvent(QPaintEvent *)
{
    //创建画家对象
    QPainter painter(this);

    //创建QPixmap对象
    QPixmap pix;
    pix.load(GAME_MAIN_SCENE);

    //绘制背景
    painter.drawPixmap(0,0,pix);


}


MainScene::~MainScene()
{
    delete ui;
}
